package com.medical.manage.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.medical.common.core.domain.Result;
import com.medical.common.core.web.page.TableDataInfo;
import com.medical.common.core.web.controller.BaseController;
import com.medical.common.log.annotation.Log;
import com.medical.common.log.enums.BusinessType;
import com.medical.common.security.annotation.RequiresPermissions;
import com.medical.manage.domain.GuidePage;
import com.medical.manage.service.GuideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;


/**
 * @BelongsProject: Medical
 * @BelongsPackage: com.medical.system.controller
 * @Author: LX
 * @CreateTime: 2025-02-26  20:30
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/page")
public class ManageController extends BaseController {
    @Autowired
    private GuideService guideService;

    /**
     * 查询引导页列表
     */
    @RequiresPermissions("manage:page:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(){
        //启动分页
        startPage();

        return getDataTable(guideService.list());
    }

    /**
     * 新增引导页
     */
    @RequiresPermissions("manage:page:add")
    @Log(title = "引导页", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody GuidePage guidePage){
        guideService.save(guidePage);
        return success();
    }

    /**
     * 删除引导页
     */
    @RequiresPermissions("manage:page:remove")
    @Log(title = "引导页", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        // 将Long数组转换为List<Long>
        List<Long> list = Arrays.asList(ids);
        guideService.removeBatchByIds(list);
        return success();
    }

    /**
     * 修改引导页
     */
    @RequiresPermissions("manage:page:edit")
    @Log(title = "引导页", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody GuidePage guidePage)
    {
        guideService.updateById(guidePage);
        return success();
    }

    /**
     * 首页轮播图
     * @return
     */
    @GetMapping("/carousel")
    public Result<List<GuidePage>> getCarousel(@RequestBody GuidePage guide) {
        LambdaQueryWrapper<GuidePage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GuidePage::getType,2).orderByAsc(GuidePage::getPageSort);
        List<GuidePage> list = guideService.list(queryWrapper);
        return Result.success(list);
    }








}
